import { App, request } from 'request'

module.exports = {
  OrderType: {
    PreparePackage: 1, /*待产包*/
    Milk: 4 /*奶粉*/
  },
  ReturnStatus: {
    NotAudit: 1, /*未审核*/
    AuditSuccess: 2, /*审核通过*/
    SendBackGoods: 3, /*退货已发回*/
    AudiFailure: 4, /*审核不通过*/
    ReceiveReturn: 5, /*收到退货*/
    Refund: 6 /*退款成功*/
  },
  isNua(callback, error) {
    request(`${App.G.Server}mall/product/nua/`, {}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  getProducts(callback, error) {
    request(`${App.G.Server}mall/product/gets/`, {}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  getMilkProducts(callback, error) {
    request(`${App.G.Server}mall/product/gets/milk/`, {}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  getProduct(pid, callback, error) {
    request(`${App.G.Server}mall/product/get/`, {pid: pid}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  saveOrder(data, callback, error) {
    request(`${App.G.Server}mall/order/save/`, data).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  prepayOrder(orderId, resetPayNo = 0, callback, error) {
    request(`${App.G.Server}mall/order/prepay/`, {
      order_id: orderId,
      reset_pay_no: resetPayNo
    }).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  payOrder(data, callback, error){
    request(`${App.G.Server}mall/order/pay/`, data).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  getOrder(orderId, callback, error) {
    request(`${App.G.Server}mall/order/get/`, {
      order_id: orderId
    }).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  getOrders(callback, error) {
    request(`${App.G.Server}mall/order/gets/`, {}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  getOrdersStatus(callback, error) {
    request(`${App.G.Server}mall/order/status/`, {}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  getAddress(callback, error) {
    request(`${App.G.Server}mall/address/get/`, {}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  saveAddress(data, callback, error) {
    request(`${App.G.Server}mall/address/save/`, data).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  getArea(code, callback, error) {
    request(`${App.G.Server}mall/address/area/`, {code: code}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  confirmReceived(orderId, type, callback, error){
    request(`${App.G.Server}mall/order/confirm/`, {
      order_id: orderId,
      type: type
    }).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  hasRedeem(callback, error){
    request(`${App.G.Server}mall/redeem/get/`, {}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  getRedeem(callback, error){
    request(`${App.G.Server}mall/redeem/get/`, {}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  pickupRedeem(callback, error){
    request(`${App.G.Server}mall/redeem/pickup/`, {}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  applyReturn(data, callback, error){
    request(`${App.G.Server}mall/return/apply/`, data).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  getReturnStatus(orderId, callback, error){
    request(`${App.G.Server}mall/return/status/`, {order_id: orderId}).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  },
  sendReturnBack(data, callback, error){
    request(`${App.G.Server}mall/return/sendBack/`, data).then(ret => {
      callback(ret)
    }).catch(ret => {
      error(ret)
    })
  }
}
